<template>
	<view class="parent-view">
		<view class="date-parent">
			<text class="date-ri-txt">{{day}}</text>
			<text class="date-zhou-txt">{{today}}</text>
			<text class="date-zhong-nian-txt">{{nongliDay}}</text>
		</view>
		<view class="jiapu-item" v-for="(item , index) in shupuList" :key="'shupu_'+index"
			 @click="shupuItemClick" :data-index="item" :style="index==0?'margin-top : 50rpx;':'margin-top : 20rpx;'">
			 <image class="item-cover" src="http://c.shiqin.wang/photo/cover_jnr.png" mode="scaleToFill"></image>
			<view class="item-content">
				<text class="item-name">{{item.title}}</text>
				<text class="item-count">家谱总人数：{{item.zong}}</text>
				<text class="item-luru">已录入纪念日：{{item.commemorationNum}}</text>
			</view>
		</view>
		<!-- <view class="scroll-view-parent">
			<scroll-view v-if="userPQD" class="jiapu-list" :scroll-x="true">
				<view class="jiapu-item" v-for="(item , index) in shupuList" :key="'shupu_'+index"
					 @click="shupuItemClick" :data-index="item">
					<image class="item-bg" src="../../static/bg_mm_book_cover.png" mode="scaleToFill"></image>
					<view class="item-content">
						<image class="item-cover" src="../../static/ic_setting_touxiang_radius.png" mode="scaleToFill"></image>
						<text class="item-name">{{item.title}}</text>
					</view>
				</view>
			</scroll-view>
		</view> -->
	<!-- 	<view v-if="userPQD" class="add-memorial-view" @click="addMemorialClick">
			<image class="add-icon" src="../../static/icon_xxjtsj.png" mode="scaleToFill"></image>
			<text class="add-txt">添加纪念日</text>
		</view>
		<view v-if="userPQD" class="memorial-list">
			<view class="memorial-item" v-for="(item , index) in memList" :key="'mem_'+index"
				 @click="memItemClick" :data-index="item">
				<image class="mem-head" :src="item.avatar"></image>
				<view class="mem-content">
					<text class="mem-item-name">{{item.title}}</text>
					<text class="mem-item-date">{{item.riqi}}</text>
				</view>
				<view class="mem-leftday">
					<text class="leftday-txt" v-if="item.surplus!==0">还有</text>
					<text class="leftday-num" v-if="item.surplus==0">今天</text>
					<text class="leftday-num" v-if="item.surplus=='未知'">0天</text>
					<text class="leftday-num" v-if="item.surplus!==0&&item.surplus!=='未知'">{{item.surplus}}天</text>
				</view>
			</view>
		</view> -->
		<LoginTipDialog :isShow="isShowLoginTip" dataSource="登录查看具体信息"  @returnLoginTipDialog="returnLoginTipDialog"/>
	</view>
</template>

<script>
	import request from '../index/request.js';
	import {getLunar} from 'chinese-lunar-calendar';
	import LoginTipDialog from "@/components/login-tip-dialog/login-tip-dialog.vue";
	export default {
		components: {
			LoginTipDialog
		},
		data() {
			return {
				shupuList:null,
				memList:null,
				day:"",
				today:"",
				nongliDay:"",
				weeks:["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
				userPQD:"",
				isShowLoginTip:false,
			}
		},
		methods: {
			returnLoginTipDialog:function(e){
				this.isShowLoginTip=e.isclose
				if(e.tag){
					uni.navigateTo({
						url:"../index/index"
					})
				}
			},
			onLoad:function(options){
				this.appUtil.saveAppInviteId(options)
				this.getTime()
			},
			onShow:function(){
				var user=uni.getStorageSync("shiqin-user")
				this.share.url='/pages/tabBar/home/index?appInviteId='+this.appUtil.getAppInviteId()
				this.share.shareType=1
				this.userPQD=user.PQD
				if (!user.PQD) {
					this.isShowLoginTip=true
				}else{
					this.GetCommemorationRiV3()
					this.GetUserTerrList()
				}
			},
			getTime:function(){
				var date = new Date()
				var year = date.getFullYear()
				var month = date.getMonth() + 1
				this.day = date.getDate()
				this.today=year+"年"+month+"月"+this.day+"日"+"  "+this.weeks[date.getDay()]
				var nongli=getLunar(year, month, this.day)
				this.nongliDay=nongli.lunarYear+"  "+nongli.dateStr
			},
			//获取数据
			GetUserTerrList:function(){
				var that=this
				request.post("api/apiv2/GetUserTerrList",{
				}).then(data=>{
					that.shupuList=data
				})
			},
			GetCommemorationRiV3:function(){
				var that=this
				request.post("api/user/GetCommemorationRiV3",{
				}).then(data=>{
					that.memList=data
				})
			},
			shupuItemClick:function(e){
				let item = e.currentTarget.dataset.index;
				uni.setStorageSync("jiapu_click_data",item)
				uni.navigateTo({
					url:"../shupu-memorial-day/index?title="+item.title+"&id="+item.id
				})
			},
			addMemorialClick:function(){
				uni.navigateTo({
					url:"../add-memorial-day/index"
				})
			},
			memItemClick:function(e){
				let item = e.currentTarget.dataset.index;
				uni.navigateTo({
					url:"../add-memorial-day/index?data="+JSON.stringify(item)
				})
			}
		}
	}
</script>

<style>
	@import "index.css";
</style>
